﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data;
using MySql.Data.MySqlClient;
using ASV.Classes;

namespace ASV.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string username = UserName.Text;
            string password = Password.Text;
            Connection mycon = new Connection();

            Authentication auth = new Authentication(mycon.getConnection());
            auth.loginStatus = auth.login(username, password);

            if (auth.successfulLoggedIn() == true)
            {
                Response.Redirect("~/Start.aspx");
                //Response.Write(HttpContext.Current.Session["kundennummer"]);
            }
            else
            {
                string errorText = "<ul><li>Die Anmeldung war fehlerhaft. Bitte überprüfen Sie ihre Kundennumer und Passwort</li></ul>";
                errors.Text = errorText;
                // ERROR Messages
            }

        }
    }
}
